﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cuyan.resume.analysis.Utlis
{
    public class RADataHelp
    {
        static object GetRADataRWLock = new object();
        public static List<string> GetRADataRW(string tableName, List<string> pinitCYs)
        {
            List<string> initCYs = new List<string>();
            //lock (GetRADataRWLock)
            //{
            //创建一个表
            string[] colNames = new string[] { "Value" };
            string[] colTypes = new string[] { "TEXT" };
            string queryString = SQLiteUtlis.CteateTableSql(tableName, colNames, colTypes);
            SQLiteUtlis s = new SQLiteUtlis();
            s.ExecuteNonQuery(queryString);
            if (pinitCYs.Count() > 0)
            {
                foreach (string initCY in pinitCYs)
                {
                    var table = s.ExecuteQuery($"select * from {tableName} where Value = '{initCY}'");
                    if (table.Rows.Count == 0)
                    {
                        s.ExecuteNonQuery($"insert into {tableName} (Value) values ('{initCY}')");
                    }
                }
            }
            if (true)
            {
                var table = s.ExecuteQuery($"select * from {tableName}");
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    initCYs.Add(table.Rows[i][0] + "");
                }
            }

            return initCYs;
            //}
        }


        public static List<string> GetRADataRW(string tableName)
        {
            List<string> initCYs = new List<string>();
            //创建一个表
            string[] colNames = new string[] { "Value" };
            string[] colTypes = new string[] { "TEXT" };
            string queryString = SQLiteUtlis.CteateTableSql(tableName, colNames, colTypes);
            SQLiteUtlis s = new SQLiteUtlis();
            s.ExecuteNonQuery(queryString);
            if (true)
            {
                var table = s.ExecuteQuery($"select * from {tableName}");
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    initCYs.Add(table.Rows[i][0] + "");
                }
            }

            return initCYs;
        }
    }
}
